<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/31 0031
 * Time: 18:21
 */

namespace app\admin\controller;


use app\index\model\LabApp;
use think\Controller;

class AdminLabApp extends Controller
{
    //中间件登录限制
    protected $middleware = [
        'AdminCheck'
    ];
    //教师当前预约列表
     public function teacher_now_list(){
         $lab_app=LabApp::hasWhere('lab',[
             'teacher_id'=>\session('teacher')['id']
         ])->where('statu',0)->paginate(10);
         $this->assign('labs',$lab_app);
         return $this->fetch();
     }
     //管理员当前预约列表
    public function admin_now_list(){
         $lab_app=new LabApp();
         $lab_app=$lab_app
             ->where('statu',0)
             ->paginate(10);
         $this->assign('labs',$lab_app);
         return $this->fetch();
    }
    //教师历史预约列表
    public function teacher_history_list(){
        $lab_app=LabApp::hasWhere('lab',[
            'teacher_id'=>\session('teacher')['id']
        ])->where('statu','neq',0)
            ->order('create_time','desc')
            ->paginate(10);
        $this->assign('labs',$lab_app);
        return $this->fetch();
    }
    //管理员历史预约列表
    public function admin_history_list(){
        $lab_app=new LabApp();
        $lab_app=$lab_app
            ->where('statu','neq',0)
            ->order('date')
            ->paginate(10);
        $this->assign('labs',$lab_app);
        return $this->fetch();
    }
    //预约审批
    public function shenhe(){
         $id=input('post.id');
         $statu=input('post.statu');
         $lab_app=new LabApp();
         $lab_app=$lab_app->save([
             'statu'=>$statu
         ],['id'=>$id]);
         if ($lab_app){
             $msg=$this->msg(200,'审核成功');
         }else{
             $msg=$this->msg(400,'审核失败');
         }
         return $msg;
    }
    private function msg($statu,$msg){
         return[
           'statu'=>$statu,
           'msg'  =>$msg
         ];
    }
}